$(function () {
    findAll();
})

function findAll() {
    $.ajax({
        url: '/back/product/findAll',
        data: {},
        type: "get",
        dataType: "json",
        success: function (data) {
            console.log(data);
            setData(data.list);
        }
    })
}

function setData(data) {
    let html = '';
    for (let i = 0; i < data.length; i++) {
        html += '<div>\n' +
            '    <div>' + data[i].id + '</div>\n' +
            '    <div>' + data[i].name + '</div>\n' +
            '    <div><img src=" ' + data[i].imgHref + '" style="width: 30px;height: 30px"></div>\n' +
            '    <div>' + data[i].normalPrice + '</div>\n' +
            '    <div>' + data[i].price + '</div>\n' +
            '    <div>' + data[i].content + '</div>\n' +
            '    <div>' + data[i].cuisineName + '</div>\n' +
            '    <div>' + data[i].enable + '</div>\n' +
            '    <div><a href="javascript:edit(' + data[i].id + ')">编辑</a> 删除</div>\n' +
            '</div>';
    }
    $(".myBody").html(html);
}

function hideImg(content) {
    let reg=/大幅度/;//正则表达式
    return content.replace(reg,"");
}
function edit(id) {
    sessionStorage.setItem("productId", id);
    $(".right").load("/html/product/productEdit.html");
}